import type { StorybookConfig } from '@storybook/vue3-vite';

import { join, dirname } from "path"

/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
function getAbsolutePath(value: string): any {
  return dirname(require.resolve(join(value, 'package.json')))
}
const config: StorybookConfig = {
  "stories": [
    "../src/**/*.mdx",
    "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"
  ],
  "addons": [
    getAbsolutePath('@chromatic-com/storybook'),
    getAbsolutePath('@storybook/addon-docs'),
    getAbsolutePath('@storybook/addon-onboarding'),
    getAbsolutePath("@storybook/addon-a11y"),
    getAbsolutePath("@storybook/addon-vitest")
  ],
  "framework": {
    "name": getAbsolutePath('@storybook/vue3-vite'),
    "options": {}
  },
  viteFinal: async (config) => {
    // 动态导入 Tailwind CSS 的 Vite 插件
    const { default: tailwindcss } = await import('@tailwindcss/vite');
    
    // 将插件添加到 Vite 配置的插件数组中
    config.plugins = config.plugins || [];
    config.plugins.push(tailwindcss());
    
    // 返回合并后的配置
    return config;
  },
};
export default config;